home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8614
/
8614.xpi
/
modules
/
application
/
ReportsManager.jsm
< prev
next >
Wrap
Text File
|
2010-02-10
|
3KB
|
114 lines
// DO NOT import this into the global namespace, but instead
// import it into your own namespace wrapper
var EXPORTED_SYMBOLS = ["REPORTS_MANAGER"];
Components.utils.import("resource://glydo/utils/prototype_xul_1_6_0_3_modified.jsm");
Components.utils.import("resource://glydo/utils/Utils.jsm");
Components.utils.import("resource://glydo/utils/Prefs.jsm");
Components.utils.import("resource://glydo/storage/LoggingDB.jsm");
var Report = Prototype.Class.create({
initialize: function(reportData,onSendSuccess) {
this.reportData = reportData;
this.onSendSuccessFunc = onSendSuccess;
},
send: function() {
var reporting_server_url = Prefs.reporting_server_url;
if (!reporting_server_url) {
return;
}
var params = {
clientId: this.reportData.report.ClientID,
};
if (Prefs.server_trace) {
params.useTrace = 1;
}
if (params = Prototype.O.toQueryString(params)) {
reporting_server_url += (Prototype.S.include(reporting_server_url,'?') ? '&' : '?') + params;
}
var reportXml = this.getReportXml();
//
// Create a new AJAX request for the report
this.ajax_request = new Prototype.Ajax.Request(
reporting_server_url, {
contentType: "text/xml",
method: 'post',
postBody: reportXml,
onSuccess: Prototype.F.bind(this.onSendSuccess,this),
onFailure: Prototype.F.bind(this.onSendFailure,this)
});
},
getReportXml: function() {
var reportDoc = Utils.toXml("Glydo.ClientPeriodicalReport",this.reportData.report);
var serializer = Components.classes["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Components.interfaces.nsIDOMSerializer);
var res = serializer.serializeToString(reportDoc);
return res;
},
onSendSuccess: function(response) {
if (!response || (response.status === 0)) {
this.onSendFailure(response);
return;
}
if ((response.status !== 200)) {
return;
}
this.onSendSuccessFunc(this.reportData);
},
onSendFailure: function(response) {
var error = response ? response.responseText : "Communication problem";
if (!error) {
error = "Communication problem";
}
}
});
var REPORTS_MANAGER = ({
init: function() {
this.sendReportIfNecessary();
this.reportingIntervalId = Utils.setInterval(REPORTS_MANAGER.sendReportIfNecessary,180000);
},
destroy: function() {
if (this.reportingIntervalId) {
Utils.clearInterval(this.reportingIntervalId);
delete this.reportingIntervalId;
}
},
sendReportIfTimeElapsed: function(report_send_interval_ms) {
var reportData = LOGGING_DB.prepareReportIfNecessary(report_send_interval_ms);
if (reportData !== null) {
reportData.report.ClientInfo = {};
var report = new Report(reportData,REPORTS_MANAGER.onReportSentSuccess);
report.send();
}
},
sendReportIfNecessary: function() {
this.sendReportIfTimeElapsed(Prefs.report_send_interval_mins*60000);
},
sendReportForce: function() {
this.sendReportIfTimeElapsed();
},
onReportSentSuccess: function(reportData) {
Glydo.LOGGING_DB.markReportAsSent(reportData);
},
});